/*
 * YuebaoBuffer.h
 *
 *  Created on: 2011-3-19
 *      Author: wangchao
 */

#ifndef YUEBAOBUFFER_H_
#define YUEBAOBUFFER_H_
#include <e32cmn.h>

class YuebaoBufferBase
{
public:
    YuebaoBufferBase( int length );
    virtual ~YuebaoBufferBase( );
protected:
    int _bufferLength;
    HBufC* _bufferPtr;
public:

    void SetMaxLength( int length );
public:
    HBufC* Buffer( );
    const TDesC& operator()( ) const;
    TPtr Des( );

    int Length( );
    void Zero( );

    void Copy( const TDesC8& aDes );
    void Copy( const TDesC16& aDes );

    void Append( TChar ch );
    void Append( const TDesC16 &aDes );
    void AppendNum( TInt64 number );
    void AppendFormat( TRefByValue< const TDesC > aFmt, ... );

    int Compare( const TDesC& aDes );

    int Find( const TDesC& aDes );
    int Locate( TChar ch );
    int LocateReverse( TChar ch );

    TPtrC Left( int length );
    TPtrC Right( int length );
    TPtrC Mid( int pos );
    TPtrC Mid( int pos, int length );

    void LowerCase( );
    void UpperCase();

    void Format( TRefByValue< const TDesC > aFmt, ... );
};

template< int S >
class YuebaoBuffer : public YuebaoBufferBase
{
public:
    YuebaoBuffer( ) :
        YuebaoBufferBase( S )
    {

    }
public:
    YuebaoBuffer& operator=( const TDesC16 &aDes )
    {
        Copy( aDes );
        return *this;
    }
};

#endif /* YUEBAOBUFFER_H_ */
